package com.shunda.trade.controller;

import com.shunda.common.core.controller.BaseController;
import com.shunda.common.core.page.TableDataInfo;
import com.shunda.trade.entity.TradeOrder;
import com.shunda.trade.service.TradeOrderService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static com.shunda.common.utils.PageUtils.startPage;

/**
 * 用户信息表(TradeOrder)表控制层
 *
 * @author makejava
 * @since 2025-03-13 21:36:37
 */
@RestController
@RequestMapping("tradeOrder")
public class TradeOrderController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TradeOrderService tradeOrderService;

    /**
     * 分页查询
     *
     * @param tradeOrder 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<TradeOrder>> queryByPage(TradeOrder tradeOrder, PageRequest pageRequest) {
        return ResponseEntity.ok(this.tradeOrderService.queryByPage(tradeOrder, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TradeOrder> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.tradeOrderService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tradeOrder 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<TradeOrder> add(TradeOrder tradeOrder) {
        return ResponseEntity.ok(this.tradeOrderService.insert(tradeOrder));
    }

    /**
     * 编辑数据
     *
     * @param tradeOrder 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<TradeOrder> edit(TradeOrder tradeOrder) {
        return ResponseEntity.ok(this.tradeOrderService.update(tradeOrder));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.tradeOrderService.deleteById(id));
    }

    /**
     * 订单创建
     */

    /**
     * 订单支付，支付成功后进行后续逻辑
     */
    @GetMapping("/paymentSuccessful")
    public String paymentSuccessful(@RequestParam("orderId") Long orderId) {
        tradeOrderService.paymentSuccessful(orderId);
        return null;
    }

    /**
     * 订单查询列表       queryByPage
     */

    /**
     * 查询订单详情        queryById
     */

    public TableDataInfo getOrderPage(TradeOrder tradeOrder) {
        startPage();
        List<TradeOrder> list = tradeOrderService.selectOrderPage(tradeOrder);
        return getDataTable(list);
    }

}

